//
//  FirstStamentOfIncomeAndExpandingController.m
//  DYKT
//
//  Created by 陈雷 on 2017/7/21.
//  Copyright © 2017年 windo. All rights reserved.
//

#import "FirstStamentOfIncomeAndExpandingController.h"
#import "StamentOfIncomeAndExpandCell.h"
#import "SecondStamentOfIncomeAndExpandingController.h"

@interface FirstStamentOfIncomeAndExpandingController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tbv;
@property (strong, nonatomic) IBOutlet UIView *headerV;

@property (weak, nonatomic) IBOutlet UILabel *accumulatedEarningsLb;// 累计收益
@property (weak, nonatomic) IBOutlet UILabel *yesterdayEarningsLb;//昨日收益

@property (nonatomic,strong) NSMutableArray *dataArr;//数据

@end

@implementation FirstStamentOfIncomeAndExpandingController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadData];//加载数据
    [self baseConfig];
}

- (void)baseConfig{
    
    self.title = @"累计收益";
    
    self.tbv = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KSCreenWidth, KSCreenHeight - 64) style:UITableViewStyleGrouped];
    self.tbv.delegate = self;
    self.tbv.dataSource = self;
    [self.view addSubview:self.tbv];
    
    self.tbv.separatorColor = [UIColor colorWithHexString:@"eeeeee"];
    self.tbv.tableFooterView = [UIView new];
    [self.tbv registerNib:[UINib nibWithNibName:@"StamentOfIncomeAndExpandCell" bundle:nil] forCellReuseIdentifier:@"StamentOfIncomeAndExpandCell"];
    self.tbv.separatorInset = UIEdgeInsetsZero;
    self.headerV.frame = CGRectMake(0, 0, KSCreenWidth, 85);
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
            return 85;
            break;
        default:
            return 50;
            break;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        return .001;
    }
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return .001;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    switch (section) {
        case 0:
            return 1;
            break;
            
        default:
            if (self.dataArr.count > 0) {
                return self.dataArr.count;
            }
            return 3;
            break;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 2;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
            [cell addSubview:self.headerV];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    
    StamentOfIncomeAndExpandCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StamentOfIncomeAndExpandCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (self.dataArr.count > 0) {
        NSDictionary *dicc = self.dataArr[indexPath.row];
        cell.timeL.text = dicc[@"date"];
        cell.priceL.text = [NSString stringWithFormat:@"%.2lf",[dicc[@"zuoRi"] floatValue]];
    }
    
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"section---%d, row---%d",indexPath.section,indexPath.row);
    
    if (indexPath.section == 0) {
        return;
    }
    SecondStamentOfIncomeAndExpandingController * vc = [[SecondStamentOfIncomeAndExpandingController alloc]init];
    if (self.dataArr.count > 0) {
        NSDictionary *dicc = self.dataArr[indexPath.row];
        vc.dateStr = dicc[@"date"];
    }
    [self.navigationController pushViewController:vc animated:YES];
    
}

#pragma mark- 加载数据
- (void)loadData{
    
//    NSString * url=[NSString stringWithFormat:BASE_URL,@"800810"];
//    
//    NSDictionary *paramDic = @{};
//    
//    NSString *paramStr = [JFDic_StringTransform dictionaryToJson:paramDic];
//    
//    [[EatShowUtil shareNetWork]getDataByAFPost:url parameters:paramStr success:^(NSDictionary *dic) {
//        
//        self.dataArr = [NSMutableArray array];
//        
//        self.accumulatedEarningsLb.text = [NSString stringWithFormat:@"%.2f",[dic[@"shouYiSumList"][@"leiJi"] floatValue]];
//        
//        self.yesterdayEarningsLb.text = [NSString stringWithFormat:@"%.2f",[dic[@"shouYiSumList"][@"zuoRi"] floatValue]];
//        
//        self.dataArr = dic[@"shouYiSumList"][@"list"];
//        
//        [self.tbv reloadData];//加载完数据刷新单元格
//        
//    } dataError:^(NSString *dataerror) {
//        
//    } netError:^(NSDictionary *errdic) {
//        
//    }];

}

@end
